﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Main.Master" AutoEventWireup="true"
    CodeBehind="View.aspx.cs" Inherits="APMS.WebSite.Views.Message.View" %>
    
<%@ Import Namespace="APMS.WebSite.Common" %>    
<%@ Import Namespace="APMS.WebSite.Models.DataStore" %>
<%@ Import Namespace="APMS.WebSite.Models.ViewData.UserControls" %>

<asp:Content ID="ScriptContent" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript" language="javascript">
//        $(document).ready(function(){
//            $('a.deleteItem').click(function() { 
//                var result = confirm("Do you really need to delete this item, the action cannot be undo?");
//                if(result) {
//                    performAction('/InProject/' + 
//                }
//            });
//        });
//        
//        // TODO: Move to common script
//        function performAction(action, args, message) {
//            $.post(action, args, function(response) {
//                $.jGrowl('Delete message successfully', {speed:  'slow'});
//            });
//        }
//        
//        function updateUserProfile(userName) {
//            $.post("/User/Update/" + userName, {
//                id: userName, 
//                password: $('#tx_password').val(), 
//                email: $('#tx_email').val(), 
//                firstName: $('#tx_firstName').val(), 
//                lastName: $('#tx_lastName').val()
//            }, function(response) {
//                $.jGrowl('Update user successfully', {speed:  'slow'});
//            });
//        }
        
	</script>
</asp:Content>
<asp:Content ID="PageTitleContent" ContentPlaceHolderID="PageTitleHolder" runat="server">
    <h2 class="nodesc"><%= Html.Encode(ViewData.Model.CurrentProject.ProjectName)%></h2>
    <h3>View Message</h3>
</asp:Content>
<asp:Content ID="NavigationMenuContent" ContentPlaceHolderID="NavigationMenuHolder" runat="server">
    <%=Html.RenderUserControl("~/Views/Shared/UserControls/MainNav.ascx", ViewData[BaseController.MAIN_NAV])%>
</asp:Content>
<asp:Content ID="CommandLinkContent" ContentPlaceHolderID="CommandLinkHolder" runat="server">
</asp:Content>
<asp:Content ID="SidebarContent" ContentPlaceHolderID="SidebarHolder" runat="server">
    <div class="widget">
        <h3 class="widgetTitle">Actions</h3>
        <ul class="widgetContent">
            <li><%=Html.ActionLink<MessageController>(x => x.Create(ViewData.Model.CurrentProject.ProjectID), "Create a new message", new { @class = "createItem" })%></li>
            <li><%=Html.ActionLink<MessageController>(x => x.Update(ViewData.Model.CurrentProject.ProjectID, ViewData.Model.CurrentMessage.MessageID), "Edit message", new { @class = "editItem" })%></li>
            <li><%=Html.ActionLink<MessageController>(x => x.Delete(ViewData.Model.CurrentProject.ProjectID, ViewData.Model.CurrentMessage.MessageID), "Delete message", new { @class = "deleteItem" })%></li>
        </ul>
    </div>
</asp:Content>
<asp:Content ID="MainContent" ContentPlaceHolderID="ContentHolder" runat="server">
    <div class="contentWrap">
    <%
        Message message = ViewData.Model.CurrentMessage;
        Project project = ViewData.Model.CurrentProject;
        List<Comment> comments = ViewData.Model.Comments;
        
        if (message != null)
        {
            StringBuilder msgBuilder = new StringBuilder();
            //string viewMessageLink = "/InProject/" + currentProject.ProjectID + "/Message/View/" + message.MessageID;

            //// Date of post
            //msgBuilder.AppendFormat("<h2 class=\"date\"><span>{0}</span></h2>",
            //    message.ModifyDate.ToString(AppHelper.DateTimeFormat));
            
            // Message Content
            msgBuilder.AppendLine("<div class=\"message details\">");
            msgBuilder.AppendFormat("<h1 class=\"title\">{0}</h1>",
                message.MessageTopic);
            msgBuilder.AppendLine("<div class=\"meta details\">");
            msgBuilder.AppendFormat("<p><span class=\"label\">From: </span>{0}</p>", message.UserName);
            msgBuilder.AppendFormat("<p><span class=\"label\">Date: </span>{0}</p>", message.ModifyDate.ToString(AppHelper.DateTimeFullFormat));
            msgBuilder.AppendLine("</div>");
            msgBuilder.AppendFormat("<div class=\"content\">{0}</div>", message.MessageDetail);
            msgBuilder.AppendLine("</div>");
            
            msgBuilder.AppendLine("<div class=\"comments\">");
            //
            foreach (Comment item in comments)
            {
                msgBuilder.AppendFormat("<div class=\"comment\"><h3 class=\"title\">{0}</h3>", item.UserName);

                // Able to delete / edit
                if (item.UserName == UserProfile.UserName)
                {
                    msgBuilder.AppendFormat("<p class=\"meta\">{0} | {1}</p>", 
                        "<a href=\"#\">Edit</a>",
                        "<a href=\"#\">Delete</a>");
                }
                
                msgBuilder.AppendFormat("<p class=\"content\">{0}</p></div>", item.CommentDetail);
                
                //msgBuilder.AppendFormat("<div class=\"comment\"><h3 class=\"title\">{0}</h3><p class=\"meta\">{2}</p><p class=\"content\">{1}</p></div>", 
                //    item.UserName, 
                //    item.CommentDetail, 
                //    item.ModifyDate.ToString(AppHelper.DateTimeFormat));
            }
            msgBuilder.AppendLine("</div>");
            // comments

            Response.Flush();
            Response.Write(msgBuilder.ToString());
        }
    %>
    </div>
    <form method="post" action="/InProject/<%=ViewData.Model.CurrentProject.ProjectID %>/Message/AddComment/<%=ViewData.Model.CurrentMessage.MessageID %>">
    <div id="mainForm">
        <h3>Comment</h3>
        <p class="blockintro">XHTML tag are allowed. However, the RichTextEditor is not ready right now. Please wait until next release.</p>
        <div class="block">
            <p><%=Html.TextArea("commentDetails", "")%></p>
        </div>
        
        <%-- Submit Action--%>
        <div class="action">
            <%-- TODO: Validate Form --%>
            <input id="bt_save" type="submit" class="button" value="Add this comment" /><span> or Cancel</span>
        </div>
    </div>
    </form>
</asp:Content>

